package com.cys.markdown.doc.admin.config;

import com.cys.markdown.doc.admin.logback.ExtHandshakeInterceptor;
import com.cys.markdown.doc.admin.logback.ExtLogWebSocketEndPoint;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * WebSocket配置
 * Created by caiyushen on 2018/8/22.
 */
@Configurable
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    //使用独立的servlet容器，而不是直接使用springBoot的内置容器，就不要注入ServerEndpointExporter，因为它将由容器自己提供和管理
    /*
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
    */


    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry.addHandler(new ExtLogWebSocketEndPoint(), "/admin/websocket/log/infos").addInterceptors(new ExtHandshakeInterceptor());
    }
}
